package orm

import (
	"fmt"
)

// 小于条件
type condLt struct {
	field string
	value interface{}
}

// 大于等于条件
type condGe struct {
	field string
	value interface{}
}

// 小于
func Lt(field string, value interface{}) Cond {
	return &condLt{
		field: field,
		value: value,
	}
}

// 大于等于
func Ge(field string, value interface{}) Cond {
	return &condGe{
		field: field,
		value: value,
	}
}

func (c *condLt) Not() Cond {
	return Ge(c.field, c.value)
}

func (c *condGe) Not() Cond {
	return Lt(c.field, c.value)
}

func (c *condLt) Gen(args *[]interface{}, param func() string, colname func(string) string) string {
	*args = append(*args, c.value)
	return fmt.Sprintf("%v < %v", colname(c.field), param())
}

func (c *condGe) Gen(args *[]interface{}, param func() string, colname func(string) string) string {
	*args = append(*args, c.value)
	return fmt.Sprintf("%v >= %v", colname(c.field), param())
}
